<!-- company表单弹窗 -->
<form id="group-form" lay-filter="group-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">小组名称</label>
        <div class="layui-input-block">
            <input name="teacid" id="teacid" type="hidden">
            <input name="grouid" id="grouid" type="hidden">
            <input name="gpname" placeholder="请输入小组名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>


    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">小组类型</label>
        <div class="layui-input-block">
            <select name="gptype" lay-verify="required">
                <option value="0">未开班</option>
                <option value="1">已开班</option>
                <option value="2">毕业</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="group-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'index', 'admin', 'form', 'formSelects'], function () {

        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var index = layui.index;

        var login_user

        // 获取当前用户信息
        index.getUser(function (user) {
            login_user = user
        });

        var group = admin.getTempData('groupData');
        form.val('group-form', group);
        console.log(group)

        form.val("group-form", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "teacid": login_user.id
        });
        // 表单提交事件
        form.on('submit(group-form-submit)', function (data) {
            layer.load(2);
            if (data.field.grouid!=null&&data.field.grouid!=''){
                admin.req('api-user/group/updateGroup', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'post');

            }else {
                admin.req('api-user/group/addGroup', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                }, 'POST');
            }

            return false;

        });
    });
</script>